package com.chwn.curiousdiary.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Myshikin on 2017/3/29.
 */
public class StringUtils {
    public static final int HOUR = 60 * 60 * 1000;
    public static final int MIN  = 60 * 1000;
    public static final int SEC  = 1000;

    /**
     * 格式化时间
     * @param time
     *         long类型的时间
     * @return 00:00:00 或者  00：00
     */
    public static String formatTime(int time) {
        int hour = time / HOUR;
        int min = time % HOUR / MIN;
        int sec = time % MIN / SEC;

        if (hour >= 1) {
            // 00:00:00
            return String.format("%02d:%02d:%02d", hour, min, sec);
        } else {
            //00：00
            return String.format("%02d:%02d", min, sec);
        }
    }

    /**
     * 获取当前系统时间
     */
    public static String formatSystemTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        return sdf.format(new Date());
    }
}
